﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

using CommonLib;

namespace CommonTest {
    class Program {
        static void Main(string[] args) {
            testVector();
        }

        private static void testVector() {
            Vector3 vec, clone, copy;
            
            vec = new Vector3();
            for (int i = 0; i < vec.Length; i++) {
                Debug.Assert(vec[i] == 0);
            }

            double[] data = { -1.0, 0.0, 1.0 };
            vec = new Vector3(data);
            for (int i = 0; i < vec.Length; i++) {
                Debug.Assert(vec[i] == data[i]);
            }

            clone = new Vector3(vec);
            clone.add(5);
            for (int i = 0; i < clone.Length; i++) {
                DoubleTester.Assert(clone[i] - 5, vec[i]);
            }

            clone.sub(5);
            for (int i = 0; i < clone.Length; i++) {
                DoubleTester.Assert(clone[i], vec[i]);
            }

            clone = new Vector3(vec);
            clone.mul(2);
            for (int i = 0; i < clone.Length; i++) {
                DoubleTester.Assert(clone[i], 2 * vec[i]);
            }

            clone = new Vector3(vec);
            clone.add(vec);
            for (int i = 0; i < clone.Length; i++) {
                DoubleTester.Assert(clone[i], 2 * vec[i]);
            }

            clone.sub(vec);
            for (int i = 0; i < clone.Length; i++) {
                DoubleTester.Assert(clone[i], vec[i]);
            }

            clone = new Vector3(0.0, -2.0, 2.0);
            copy = new Vector3(clone);
            DoubleTester.Assert(clone.norm(), copy.norm());
            DoubleTester.Assert(clone.dot(clone), copy.dot(clone));
            DoubleTester.Assert(Math.Sqrt(clone.dot(clone)), copy.norm());

            clone = new Vector3(vec);
            DoubleTester.Assert(clone.normalize().norm(), 1.0);
        }
    }
}
